﻿using System;
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Interfaces.Enums;

namespace EconomicInformationServiceWcf.ServiceBehaviours
{
    [AttributeUsage(AttributeTargets.Method)]
    public class EISAutorizeAttribute : Attribute, IOperationBehavior
    {
        public RoleType[] Permissions { get; set; }
        
        public void Validate(OperationDescription operationDescription)
        {}

        public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
        {
            var inspector = new EISAutorizeParameterInspector(Permissions);
            dispatchOperation.ParameterInspectors.Add(inspector);
        }

        public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
        {}

        public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
        {}
    }
}